// SessionLauncher.h

#pragma once
#include <vcclr.h>

using namespace System;

DWORD Spawn(wchar_t * exe, wchar_t *cmd, bool runInConsoleSession, bool waitForExit);

namespace SessionLauncher {
	public ref class Launcher
	{
	public:
		void Run(System::String^ applicationName, System::String^ cmdWithParamenters, bool runInConsoleSession, bool waitForExit) {
			wchar_t* appNamePointer = (wchar_t*)ToUnmanged(applicationName);
			wchar_t* cmdPointer = (wchar_t*)ToUnmanged(cmdWithParamenters);
			//int result = 0;
			DWORD result = ::Spawn(appNamePointer, cmdPointer, runInConsoleSession, waitForExit);
			if (result != 0)
				throw gcnew System::ComponentModel::Win32Exception(result);
		}
	
		const wchar_t* ToUnmanged(System::String ^str) {
			pin_ptr<const wchar_t> convertedValue = PtrToStringChars(str);  // <-- #include <vcclr.h>
			const wchar_t *constValue = convertedValue;
			return constValue;
		}


		
		// TODO: Add your methods for this class here.
	};
}
